import axios from 'axios';
import Keycloak from 'keycloak-js';

const baseurl = 'http://localhost/camunda';
//var token;

async function initKeycloak() {
  const keycloak = new Keycloak();
  console.log('set keycloak');
  await keycloak.init({onLoad: 'login-required'});
  return keycloak.token;
}

$(document).ready(async function () {
  var token = await initKeycloak();
  axios.create({withCredentials: true}).get(
    baseurl + '/engine-rest/process-definition', 
    {headers: {'Content-Type':'application/json', 'Authorization': 'Bearer '+token}}
    ).then(
      res=>{
        console.log(res.data);
        $('#dataTable').DataTable({
          data: res.data,
          columns: [
            {
              data: "id",
              render: function(data) {
                return '<a href="' + 'processinstance.html?id=' + data + '">' + data + '</a>';
              }
            },
            {data: "name"},
            {data: "description"},
            {data: "version"}
          ]
        });
      }
    )
});
  